package com.example.task2.customer;

import com.example.task2.exception.NotFoundException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CustomerService {
    private final static Logger LOGGER= LoggerFactory.getLogger(CustomerService.class);
    private final CustomerDao customerDao;
@Autowired
    public CustomerService(CustomerDao customerDao) {

        this.customerDao = customerDao;
    }

    List<Customer> getCustomers(){
        LOGGER.info("getCustomers called");
        return customerDao.findAll();
    }
    Customer getCustomer(Long id){
       return customerDao
               .findById(id)
               .orElseThrow(()-> {
                   NotFoundException notFoundException= new NotFoundException("customer 无法找到" + id);
                   LOGGER.error("error:getCustomers{}" + id,notFoundException);
                   return notFoundException;
               });
    }
}
